import { refreshToken } from "@/api/login";
import { getMenuList } from "@/api/menu";
import { getUserPage } from "@/api/user";
import { setToken } from "@/utils";
import { Button, Space } from "antd";
import { Component } from "react";

export default class Console extends Component {
  render() {
    return (
      <Space>
        <Button type="primary" onClick={this.handleThree}>
          并发请求
        </Button>

        <Button onClick={this.handleOne}>调用菜单列表接口</Button>
        <Button onClick={this.handleTwo}>调用用户Page接口</Button>

        <Button onClick={this.handleRefresh}>刷新TOKEN</Button>
      </Space>
    );
  }

  handleThree = () => {
    getMenuList();
    getUserPage({});
  };

  handleOne = () => {
    getMenuList().then(() => {
      console.log("菜单成功");
    });
  };

  handleTwo = () => {
    getUserPage({}).then(() => {
      console.log("角色成功");
    });
  };

  handleRefresh = () => {
    refreshToken().then((resp) => {
      console.log("resp 刷新成功", resp);
      // 将新的 TOKEN 再设置到 本地存储中
      setToken(resp.token);
    });
  };
}
